package com.geektime.hello;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @Date 2020-10-26 13:47
 * @Author Pzy
 * @Description
 */
public class ReflectDemo {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        //三种方式 获取Class对象
        Class clazz1 = String.class;
        Class clazz2 = "Hello".getClass();
        Class clazz3 = Class.forName("java.lang.String");
        System.out.println("clazz1 = " + clazz1);
        System.out.println("clazz2 = " + clazz2);
        System.out.println("clazz3 = " + clazz3);

        Method m = Integer.class.getMethod("parseInt", String.class);
        Integer n = (Integer) m.invoke(null, "12345");
        System.out.println("n = " + n);

        Class clazz4 = Integer.class;
        Class[] classes = clazz4.getInterfaces();
        for (Class clazz : classes) {
            System.out.println("clazz = " + clazz);
        }
    }
}
